
;===========================================================================
;==  FASTT source code debugger - FAST v2.00+				  ==
;==  Written by Peter Campbell 1989.					  ==
;===========================================================================

#short
var m,t_base,seg_ft
var32 addr,addrs

fcom	 ? 64
work	 ? 64
sets	 ? 50*2
setsn	 ? 50*64
cmd_line ? 120
buffer	 ? 650
lines	 ? 24*2

dos 35(3):o3=reg bx:s3=reg es

proc abort
    {
    print bios "... Terminated."
    reg dx=o3,ds=s3:dos 25(3)
    reg ds=reg cs
    terminate
    }

on error
    {
    print bios
    error msg "\dos.err"
    print bios "!"
    abort
    }

on break error 999

function find_file(fh)
    {
    am=t_base
    ffloop:
    if seg_ft[am+1]=0 then return 0
    if seg_ft[am]b=fh then return 1
    am+=6
    goto ffloop
    }

function find_address(fm)
    {
    am=t_base
    faloop:
    n=seg_ft[am+1]
    if n=0 then return 0
    if n=fm then return am
    am+=6
    goto faloop
    }

function get_buffer
    {
    gf=seg_ft[m]b
    fp=sets+gf*2
    mn=setsn+gf*64
    handle#1,peek fp
    a1=seg_ft[m+3]
    a2=seg_ft[m+5]b
    addrs=a2*65536
    addrs+=a1

    r=search 24 from lines for a1 ;low addrs
    if r then return 1+(r-lines)/2

    addr=addrs
    seek #1,addr
    l=read #1,640 to buffer
    pokeb buffer+l,26
    return 1
    }

proc show_buffer
    {
    colour 15
    fill 80 from video|0 with 0f20h
    locate 0,0:print " -FASTT file: ";:prints mn,0
    md=buffer:ml=lines:mlo=low addr-buffer
    colour 7
    for yp=1 to 24
    locate yp,0
    poke ml,mlo+md:ml+=2
    md=printm md,80
    next yp
    }

print bios "FastT ";

seg_ft=allocate 4096

m=81h:f=fcom
mstore=0
while peekb m<>13
    {
    c=peekb m
    if c>' ' then
	{
	mstore=1
	pokeb f,c:f++:if f>(fcom+63) then goto use_file
	}
    else if mstore then goto use_file
    m++
    }

use_file:
pokeb f,0
if mstore=0 then print bios "file?":abort
moveb 120 from m to cmd_line

print bios "running ";
m=fcom
while (peekb m<>0) and (peekb m<>'.') print bios chr ucase peekb m;:m++
pokeb m,'.':print bios cr lf
m++
move 32 from fcom to work
moveb 4 from ext_com to m
moveb 3 from ext_ft to work+m-fcom

open #1,work
rl=read #1,65500 to seg_ft|0
close #1
seg_ft[rl+1]=0 ;Set end marker.
modify seg_ft to 1+rl/16

m=sets:fp=1:mn=setsn
sources=seg_ft[0]b
t_base=1+sources*64
print bios "Source file(s) ";
for so=1 to sources
    move 32 from seg_ft|fp to work
    move 32 from work	   to mn
    p=work:while peekb p<>'.' print bios chr ucase peek p;:p++
    print bios " ";
    if find_file(so-1) then
	{
	open #1,work
	poke m,handle#1
	}
    m+=2:mn+=64
    fp+=64
next so

print bios
poke exe_com+4,reg cs
poke exe_com+8,reg cs
poke exe_com+12,reg cs

setint 3 to fast3
show=1:using=0

execute fcom,exe_com

page 0
abort

;= Data ====================================================================

ext_com:
datab 'com',0

ext_ft:
datab 'ft',0

exe_com:
data 0
data cmd_line,0
data 5ch,0
data 6ch,0

;== Fast3 =========================================================================

fast3:
pushall

reg ds=reg cs
if using then goto exit3
using=1
ip=peek reg ss|(reg sp+20)
cs=peek reg ss|(reg sp+22)

if show then
    {
    m=find_address(ip)
    if m then
	{
	hy=get_buffer
	show_buffer
	m=hy*160+1
	repeat 80 video[m]b=120:m+=2
	wait for keyscan
	test break
	}
    }

;Call ON TRACE statement.
if cs[113h] then
    {
    push reg cs
    push ret_trace
    push cs
    push cs[113h]
    reg ds=cs,es=cs
    retf
    ret_trace:
    reg ds=reg cs
    }

show=1
if peekb 0|417h and 16 then show=0

using=0

exit3:
popall
iret
